package com.demohomework.homeworkdemo.mapper;

import com.demohomework.homeworkdemo.pojo.Teacher;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TeacherMapper {
    // 根据用户名查询教师信息
    @Select("SELECT * FROM teacher WHERE username = #{username}")
    Teacher findbyUsername(String username);

    // 新增教师信息
    @Insert("INSERT INTO teacher (username, password) VALUES (#{username}, #{md5Password})")
    void add(String username, String md5Password);

    // 更新教师信息
    @Update("update teacher set username = #{username}, email = #{email},name = #{name},phone = #{phone},title = #{title}, updated_at = now()" +
            " where id = #{id}")
    void update(Teacher teacher);
    //更新密码
    @Update("update teacher set password = #{md5Password} where id = #{id}")
    void updatePwd(String md5Password, Integer id);

    // 查询所有教师信息
    @Select("Select * from teacher")
    List<Teacher> list();

    @Delete("delete from teacher where id = #{id}")
    void delete(Integer id);

    //新增教师信息
    @Insert("INSERT INTO teacher (username, password, email, name, phone,title, created_at, updated_at) VALUES (#{username}, #{password}, #{email}, #{name}, #{phone},#{title}, now(), now())")
    void teaAdd(Teacher teacher);

    //根据id查询教师信息
    @Select("SELECT * FROM teacher WHERE id = #{id}")
    Teacher get(Integer id);
}
